<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="common/include :: header('文章列表')"/>
    <th:block th:include="common/include :: layout-latest-css"/>
    <th:block th:include="common/include :: ztree-css"/>
</head>
<body class="gray-bg">
<div class="ui-layout-west">
    <div class="box box-main">
        <div class="box-header">
            <div class="box-title">
                <i class="fa icon-grid"></i> 文章目录
            </div>
            <div class="box-tools pull-right">
                <a type="button" class="btn btn-box-tool" href="#" onclick="catalog()" title="管理目录"><i
                        class="fa fa-edit"></i></a>
                <button type="button" class="btn btn-box-tool" id="btnExpand" title="展开" style="display:none;"><i
                        class="fa fa-chevron-up"></i></button>
                <button type="button" class="btn btn-box-tool" id="btnCollapse" title="折叠"><i
                        class="fa fa-chevron-down"></i></button>
                <button type="button" class="btn btn-box-tool" id="btnRefresh" title="刷新目录"><i
                        class="fa fa-refresh"></i></button>
            </div>
        </div>
        <div class="ui-layout-content">
            <div id="tree" class="ztree"></div>
        </div>
    </div>
</div>

<div class="ui-layout-center">
    <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="article-form">
                    <input type="hidden" id="catalogId" name="catalogId">
                    <input type="hidden" id="parentId" name="parentId">
                    <div class="select-list">
                        <ul>
                            <li>
                                文章标题：<input type="text" name="title"/>
                            </li>
                            <li>
                                文章标签：<input type="text" name="articleTags"/>
                            </li>
                            <li>
                                是否发布：<select name="isRelease" th:with="type=${@dict.getType('sys_yes_no')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                            </li>
                            <li>
                                是否评论：<select name="isDiscuss" th:with="type=${@dict.getType('sys_yes_no')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                            </li>
                            <li>
                                文章类型：<select name="articleType" th:with="type=${@dict.getType('content_article_type')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                            </li>
                            <li class="select-time">
                                <label>创建时间： </label>
                                <input type="text" class="time-input" id="startTime" placeholder="开始时间"
                                       name="params[beginTime]"/>
                                <span>-</span>
                                <input type="text" class="time-input" id="endTime" placeholder="结束时间"
                                       name="params[endTime]"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                        class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                        class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.addTab()" shiro:hasPermission="content:article:add">
                    <i class="fa fa-plus"></i> 新增
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.editTab()"
                   shiro:hasPermission="content:article:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()"
                   shiro:hasPermission="content:article:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
            </div>

            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
</div>

<th:block th:include="common/include :: footer"/>
<th:block th:include="common/include :: layout-latest-js"/>
<th:block th:include="common/include :: ztree-js"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('content:article:edit')}]];
    var removeFlag = [[${@permission.hasPermi('content:article:remove')}]];
    var prefix = ctx + "content/article";
    var module = "article";

    $(function () {
        var panehHidden = false;
        if ($(this).width() < 769) {
            panehHidden = true;
        }
        $('body').layout({initClosed: panehHidden, west__size: 185});
        queryArticleList();
        queryCatalogTree();
    });

    function queryArticleList() {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            sortName: "createTime",
            sortOrder: "desc",
            modalName: "文章",
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: '文章ID',
                    visible: false
                },
                {
                    field: 'title',
                    title: '文章标题',
                    sortable: true
                },
                {
                    visible: editFlag == 'hidden' ? false : true,
                    title: '是否发布',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return releaseTools(row);
                    }
                },
                {
                    visible: editFlag == 'hidden' ? false : true,
                    title: '是否可以评论',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return discussTools(row);
                    }
                    //field: 'isDiscuss',
                },
                {
                    field: 'desca',
                    title: '描述',
                },
                {
                    field: 'updateTime',
                    title: '更新时间',
                    sortable: true
                },
                {
                    field: 'createTime',
                    title: '创建时间',
                    sortable: true
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.editTab(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a> ');
                        var more = [];
                        more.push("<a class='btn btn-default btn-xs ' href='javascript:void(0)' onclick=''><i class='fa fa-key'></i>预览</a> ");
                        if (row.isTop == 'Y') {
                            more.push("<a class='btn btn-default btn-xs " + editFlag + "' href='javascript:void(0)' onclick='toNoTop(" + row.id + ")'><i class='fa fa-check-square-o'></i>置顶</a>");
                        } else {
                            more.push("<a class='btn btn-default btn-xs " + editFlag + "' href='javascript:void(0)' onclick='toTop(" + row.id + ")'><i class='fa fa-square-o'></i>置顶</a>");
                        }
                        actions.push('<a tabindex="0" class="btn btn-info btn-xs" role="button" data-container="body" data-placement="left" data-toggle="popover" data-html="true" data-trigger="hover" data-content="' + more.join('') + '"><i class="fa fa-chevron-circle-right"></i>更多操作</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    }

    function queryCatalogTree() {
        var url = ctx + "content/catalog/treeData";
        var options = {
            url: url,
            expandLevel: 2,
            onClick: zOnClick,
            ajaxParams: {
                module: module
            }
        };
        $.tree.init(options);

        function zOnClick(event, treeId, treeNode) {
            $("#catalogId").val(treeNode.id);
            $("#parentId").val(treeNode.pId);
            $.table.search();
        }
    }

    $('#btnExpand').click(function () {
        $._tree.expandAll(true);
        $(this).hide();
        $('#btnCollapse').show();
    });

    $('#btnCollapse').click(function () {
        $._tree.expandAll(false);
        $(this).hide();
        $('#btnExpand').show();
    });

    $('#btnRefresh').click(function () {
        queryCatalogTree();
    });

    /* 文章管理-目录 */
    function catalog() {
        var url = ctx + "content/catalog?module=" + module;
        $.modal.openTab("目录管理", url);
    }

    /* 文章展示 */
    function releaseTools(row) {
        if (row.isRelease == "N") {
            return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enableRelease(\'' + row.id + '\')"></i> ';
        } else {
            return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disableRelease(\'' + row.id + '\')"></i> ';
        }
    }

    /* 文章展示-启用 */
    function enableRelease(id) {
        $.modal.confirm("确认要展示文章吗？", function () {
            $.operate.post(prefix + "/change", {"id": id, "isRelease": "Y"});
        })
    }

    /* 文章展示-停用 */
    function disableRelease(id) {
        $.modal.confirm("确认要隐藏文章吗？", function () {
            $.operate.post(prefix + "/change", {"id": id, "isRelease": "N"});
        })
    }

    /* 文章评论 */
    function discussTools(row) {
        if (row.isDiscuss == "N") {
            return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enableDiscuss(\'' + row.id + '\')"></i> ';
        } else {
            return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disableDiscuss(\'' + row.id + '\')"></i> ';
        }
    }

    /* 文章评论-启用 */
    function enableDiscuss(id) {
        $.modal.confirm("确认要开启评论吗？", function () {
            $.operate.post(prefix + "/change", {"id": id, "isDiscuss": "Y"});
        })
    }

    /* 文章评论-停用 */
    function disableDiscuss(id) {
        $.modal.confirm("确认要禁止评论吗？", function () {
            $.operate.post(prefix + "/change", {"id": id, "isDiscuss": "N"});
        })
    }

    /* 文章置顶-取消 */
    function toNoTop(id) {
        $.modal.confirm("确认要取消置顶文章吗？", function () {
            $.operate.post(prefix + "/change", {"id": id, "isTop": "N"});
        })
    }

    /* 文章置顶-置顶 */
    function toTop(id) {
        $.modal.confirm("确认要置顶文章吗？", function () {
            $.operate.post(prefix + "/change", {"id": id, "isTop": "Y"});
        })
    }
</script>
</body>
</html>
